package com.hw.controller.task;

import com.hw.entity.dto.task.TaskDTO;
import com.hw.entity.query.task.TaskQuery;
import com.hw.entity.dto.task.TaskTimeDTO;
import com.hw.model.ResponseResult;
import com.hw.service.task.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 任务表 Controller
 *
 * @author xuguang
 * @date 2021-06-28
 */
@Api(tags = "点餐订单")
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @ApiOperation(value = "获取分页列表")
    @PostMapping("/getPageListByUser")
    public ResponseResult<?> getPageListByUser(@RequestBody TaskQuery taskQuery) {
        return ResponseResult.success(taskService.getTaskListByUser(taskQuery));
    }

    @ApiOperation(value = "根据任务码获取任务详情")
    @GetMapping("/getTaskDetail")
    public ResponseResult<?> getTaskDetail(String taskId) {
        return ResponseResult.success(taskService.getTaskDetail(taskId));
    }

    @ApiOperation(value = "获得默认的点餐标题")
    @GetMapping("/getDefaultTaskTitle")
    public ResponseResult<?> getDefaultTaskTitle() {
        return taskService.getDefaultTaskTitle();
    }

    @ApiOperation(value = "发起点餐")
    @PostMapping("/generate")
    public ResponseResult<?> generatorTask(@RequestBody TaskDTO dto) {
        return taskService.generatorTask(dto);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public ResponseResult<?> delete(String taskId) {
        taskService.delete(taskId);
        return ResponseResult.success();
    }

    @ApiOperation(value = "根据点餐码查询时间")
    @GetMapping("/getEndTime")
    public ResponseResult<?> getEndTime(String taskId) {
        return ResponseResult.success(taskService.getEndTime(taskId));
    }

    @ApiOperation(value = "修改时间")
    @PostMapping("/updateTime")
    public ResponseResult<?> updateTime(@RequestBody TaskTimeDTO taskTimeDTO) {
        return taskService.updateTime(taskTimeDTO);
    }

    @ApiOperation(value = "提前结束")
    @GetMapping("/endNow")
    public ResponseResult<?> endNow(String taskId) {
        return taskService.endNow(taskId);
    }

//    @ApiOperation(value = "判断任务码是否有效")
//    @GetMapping("/valid")
//    public ResponseResult<?> valid(String code) {
//        return taskService.valid(code);
//    }

    @ApiOperation(value = "根据任务码获取商家信息")
    @GetMapping("/getStoreInfo")
    public ResponseResult<?> getStoreInfo(String taskId) {
        return ResponseResult.success(taskService.getStoreInfo(taskId));
    }

    @ApiOperation(value = "获取正在进行中的所有点餐")
    @GetMapping("/getAllOngoingTask")
    public ResponseResult<?> getAllOngoingTask() {
        return ResponseResult.success(taskService.getAllOngoingTask());
    }
}
